# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>

pkgname=deepin-api
pkgver=5.5.32
pkgrel=1
pkgdesc='Golang bindings for dde-daemon'
arch=('loong64' 'x86_64')
url="https://github.com/linuxdeepin/dde-api"
license=('GPL3')
# alsa-utils: alsactl used in sound-theme-player
# bc: used in adjust-grub-theme
# fontconfig: fc-match used in adjust-grub-theme
# librsvg: rsvg-convert used in adjust-grub-theme
# util-linux: rfkill used in device
depends=('alsa-utils' 'bc' 'fontconfig' 'glib2' 'gdk-pixbuf-xlib' 'gtk3' 'libcanberra-pulse'
         'librsvg' 'libxi' 'libxfixes' 'poppler-glib' 'util-linux' 'xcur2png' 'blur-effect')
makedepends=('git' 'deepin-gettext-tools' 'golang-deepin-gir' 'golang-deepin-lib'
             'golang-github-fsnotify-fsnotify' 'golang-github-linuxdeepin-go-dbus-factory'
             'golang-github-linuxdeepin-go-x11-client' 'golang-github-nfnt-resize'
             'golang-github-stretchr-testify' 'golang-gopkg-yaml.v3' 'bzr' 'go-pie')
provides=('golang-deepin-dde-api')
groups=('deepin')
install=deepin-api.install
options=('!lto')
source=("$pkgname-$pkgver.tar.gz::https://github.com/linuxdeepin/dde-api/archive/$pkgver.tar.gz"
        deepin-api.sysusers)
sha512sums=('a71b836bac72bc49433902b1e86090dd838250c71cf6788d3989153de8e37c95e1636b4d9df4b3c597e11eb22300f26f1f56af9b5b8842011802b85fdef548fd'
            'e894eb3928af9e244fa78010fdf16c8abb6ce18df114cf05327d02b18774d6ba5b023e4dfa0d07042f4e44a5c6e2ddb55b07f3e0db466a0e6169b52465fdefd6')

export GO111MODULE=off

prepare() {
  export GOPATH="$srcdir/gobuild:/usr/share/gocode"
  mkdir -p gobuild/src/github.com/linuxdeepin
  cp -a dde-api-$pkgver gobuild/src/github.com/linuxdeepin/dde-api

  go get github.com/cryptix/wav github.com/godbus/dbus github.com/disintegration/imaging \
         github.com/fogleman/gg github.com/mattn/go-sqlite3 github.com/gosexy/gettext \
         github.com/rickb777/date github.com/youpy/go-wav
}

build(){
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"

  cd dde-api-$pkgver
  make
}

package() {
  cd dde-api-$pkgver
  make DESTDIR="$pkgdir" SYSTEMD_LIB_DIR=/usr/lib install

  install -Dm644 ../deepin-api.sysusers "$pkgdir"/usr/lib/sysusers.d/deepin-api.conf
}
